package work20241202_chap5oop.k_duotai;

/**
 * @author zdl
 * @date 2024/12/2
 */
class Person{
    public void feed(Pet pet){
        pet.eat();
        if (pet instanceof Dog){
            Dog dog = (Dog)pet; //向下转型
            dog.swim();
        }
        if (pet instanceof Cat){
            Cat cat = (Cat)pet;
            cat.play();
        }

    }
}
class Pet{
    public void eat(){

    }
}
class Dog extends Pet{
    @Override
    public void eat() {
        System.out.println("狗吃牛肉");
    }
    public void swim(){
        System.out.println("狗会游泳");
    }
}
class Cat extends Pet{
    @Override
    public void eat() {
        System.out.println("猫吃鱼干");
    }
    public void play(){
        System.out.println("猫会玩儿");
    }
}
public class Demo14 {
    public static void main(String[] args) {
        Person person = new Person();
        person.feed(new Dog());
        person.feed(new Cat());
    }
}
